#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int M=0;
int B[40005];
int a3[40005],a5[40005];
long exp5[]={1,5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};//14
long exp3[]={1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489,1162261467};//20
int isExp3(long x){
    if(x>exp3[19] || x<exp3[0])return 0;
    if(x==exp3[0] || x==exp3[19])return 1;
    int tg,l=0,r=19;
    do{
        tg=(l+r)/2;
        if(x==exp3[tg])return 1;
        if(x<exp3[tg])r=tg;
        else l=tg;
    }while(r-l>2);
    return 0;
}
int isExp5(long x){
    if(x>exp5[13] || x<exp5[0])return 0;
    if(x==exp5[0] || x==exp5[13])return 1;
    int tg,l=0,r=13;
    do{
        tg=(l+r)/2;
        if(x==exp5[tg])return 1;
        if(x<exp5[tg])r=tg;
        else l=tg;
    }while(r-l>2);
    return 0;
}
void input(){
    int i,num3=0,num5=0,n;
    FILE *fp=fopen("235.INP","r");
    fscanf(fp,"%ld",&n);
    for(i=0;i<=n;i++){
        fscanf(fp,"%ld",&B[M+1]);
        if(isExp5(B[M+1])){
            B[M+1]=5;
            num5++;
            M++;
            a3[M+1]=num3;
            a5[M+1]=num5;
        }else if(isExp3(B[M+1])){
            B[M+1]=3;
            num3++;
            M++;
            a3[M+1]=num3;
            a5[M+1]=num5;

        }
    }
    a3[M+1]=num3;
    a5[M+1]=num5;
    fclose(fp);
}
long findb(){
    int i,j;
    long num=0;
    for(i=1;i<M;i++)
        for(j=2;j+i<=M+1;j<<=1)
            if(a3[i+j]-a3[i]==a5[i+j]-a5[i])num++;
    return num;
}
void output(long result1,long result2){
    FILE *fp=fopen("235.OUT","w");
    fprintf(fp,"%ld\n%ld",result1,result2);
    fclose(fp);
}
int main(){
    input();
    output(M,findb());
    //system("pause");
    return 0;
}

